package com.itheima.demo02;

import java.io.*;

//字符缓冲流特有功能
public class CharClass04 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        BufferedWriter bw = null;
        BufferedReader br = null;
        try {
            bw = new BufferedWriter(new FileWriter("day12\\d.txt"));
            bw.write("我又一只小毛驴");
            bw.newLine();
            bw.write("我从来都不骑");
            bw.newLine();
            bw.write("有一天我心血来潮骑它去赶集");
            bw.newLine();
            bw.write("der。。。驾。。。。");

            //这块必须加入刷新，因为输入流并没有关闭，所以没有经过刷新文件里不会有任何东西，也就读不出东西
            bw.flush();
            br = new BufferedReader(new FileReader("day12\\d.txt"));
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (bw != null) {
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("程序运行了" + (end - start) + "毫秒！");
    }
}
